<% if current_user && current_user.chat_enabled %>

<div id="chat_wrapper"> 

  <div id="chat_partial">    
  </div>
  
  <div id="chat_divs">  
    <div id="chat_div">
    </div>
  </div>
  
  <section id="chat_connecting">
    <header> 
      <%=image_tag("chat-off.png", :class => "header_icon")%>
      
      <%=t('chat.connecting')%>
    </header>
  </section>
  
  <article id="chat_connection_off">
    <header>
      <%=image_tag("chat-off.png", :class => "header_icon")%>
      <p id="chat_header_title">
        <%=t('chat.disconnected')%>
      </p>
    </header>

    <div class="chat_off">
      <div id="passwordFormChat">
        <label for="user_password" class="chatPasswordTitle">
          <%=t('chat.password')%>
        </label>
        <input id="user_password" class="chat_password" type="password">
        </input>
      </div>
      <input type="submit" class="btn storePass connectChatButton" value="Connect">
    </div>  
  </article>
  
  <div id="chat_widgets">
    <header>
      <%=image_tag("chat-off.png", :class => "header_icon")%>
    
      <%=t('chat.title')%>
    </header>
      
    <div id="status" class="dropdown">
      <dt>
        <a href="">
          <span>
            <%=t('chat.status.choose')%>
          </span>
        </a>
      </dt>
      <dd>
        <ul id="statusList">
          <li>
            <a id="available" href="#" class="option">
              <span class="badge available">
              </span>
              <%=t('chat.status.available')%>
            </a>
          </li>
          <li>
            <a id="away" href="#" class="option">
              <span class="badge away">
              </span>
              <%=t('chat.status.away')%> 
            </a>
          </li>
          <li>
            <a id="dnd" href="#" class="option">
              <span class="badge dnd">
              </span>
              <%=t('chat.status.dnd')%> 
            </a>
          </li>
          <li>
            <a id="offline" href="#" class="option">
              <span class="badge offline">
              </span> 
              <%=t('chat.status.offline')%> 
            </a>
          </li>
        </ul>
      </dd>
    </div>
      
    <div class="searchChatContacts">
      <select id="search_chat_contact" class="flexselect">
        <option value="">
          ""
        </option>
      </select>
    </div>
  </div>
  <div>
    <div id="publisherID">
    </div>
  </div>
</div>


<script type="text/javascript">

  //Global variables
  var cookie = "AuthenticationByCookie>>" + "<%=cookies[Rails.application.config.session_options[:key]]%>";
  var BOSH_SERVICE = '<%= SocialStream::Presence.bosh_service || root_url + "http-bind/" %>';
  var user_name = '<%=current_user.name%>';
  var user_slug = '<%=current_user.slug%>';
  var user_jid = PRESENCE.XMPPClient.getJidFromSlug('<%=current_user.slug%>');
  

  $(document).ready(function () {
    
        //Inicial field
        $("#chat_connecting").hide();
        $("#chat_connection_off").hide();
        $("#chat_widgets").hide();
        $("#statusList").hide();
        $("#chat_partial").html($("#chat_connecting").html())
        
        if((PRESENCE.PERSISTENCE.getRestoreUserChatStatus()!="offline")&&(cookie)){
          if (PRESENCE.XMPPClient.authByCookie()) {
            PRESENCE.XMPPClient.connectToChat(user_jid,cookie);
          } else {
            PRESENCE.XMPPClient.connectToChat(user_jid);
          }
          initialTimer = setTimeout("PRESENCE.UIMANAGER.updateChatWindow()", 10000);
        } else {
          PRESENCE.UIMANAGER.updateChatWindow();
        }
        
        PRESENCE.CORE.init();
      });
  
  </script>

  <script type="text/javascript">
  $(document).ready(function () {
    PRESENCE.WINDOW.createMainChatBox();
    PRESENCE.WINDOW.addContentToMainChatBox(PRESENCE.WINDOW.modifyChatPartialIfMainBox($("#chat_partial")));
    $("#chat_wrapper").find("#chat_partial").remove();
  });
  </script>

  <% if defined?(group)!=nil and group %>
  <script type="text/javascript">
  var current_group_slug = '<%=group.slug%>';
  </script>
  <% end %>


  <% end %>
